
package org.ricks.ioc.definition;

import org.ricks.ioc.*;
import org.ricks.ioc.anno.Bean;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;

/**
 * 启动配置Bean的定义.
 *
 */
public class ConfigurationBeanDefinition extends DefaultBeanDefinition {

    public ConfigurationBeanDefinition( Class<?> klass) {
        super( klass);
        Method[] methods = klass.getDeclaredMethods();
        for (Method method: methods) {
            Bean cfgBean = method.getAnnotation(Bean.class);
            if(Objects.isNull(cfgBean)) continue;
//            Class<?> beanKlass = method.getReturnType();
            try {
                method.setAccessible(true);
                Object obj = method.invoke(getBean());
                RicksContext.me().analytical(obj);
            } catch (InvocationTargetException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }

}